﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;

namespace Swin_e_mon_Forms
{
    partial class Creater : Form
    {
        private CommandProcessor cp;
        private Player p;
        private SwinEForm f;

        public Creater(CommandProcessor cp, Player p, SwinEForm f)
        {
            InitializeComponent();
            this.Text = "Creater";
            this.p = p;
            this.cp = cp;
            this.f = f;
        }

        #region Assembly Attribute Accessors

        public string AssemblyTitle
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
                if (attributes.Length > 0)
                {
                    AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
                    if (titleAttribute.Title != "")
                    {
                        return titleAttribute.Title;
                    }
                }
                return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
            }
        }

        public string AssemblyVersion
        {
            get
            {
                return Assembly.GetExecutingAssembly().GetName().Version.ToString();
            }
        }

        public string AssemblyDescription
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyDescriptionAttribute)attributes[0]).Description;
            }
        }

        public string AssemblyProduct
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyProductAttribute)attributes[0]).Product;
            }
        }

        public string AssemblyCopyright
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
            }
        }

        public string AssemblyCompany
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCompanyAttribute)attributes[0]).Company;
            }
        }
        #endregion

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void AboutBox1_Load(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void createItem_Click(object sender, EventArgs e)
        {
            string missing = "Missing the Following: \n\n";
            List<String> idList = new List<String>();
            if (id1.Text != "") idList.Add(id1.Text);
            if (id2.Text != "") idList.Add(id2.Text);
            if (id3.Text != "") idList.Add(id3.Text);
            Item itm = new Item(idList.ToArray(),isContainer.Checked);
            itm.IsStationary = isStationary.Checked;
            itm.Title = title.Text;
            itm.Description = desc.Text;
            if (idList.Count == 0) missing += "[Identifiers] \n";
            if (itm.Title == "") missing += "[Title] \n";
            if (itm.Description == "") missing += "[Description] \n";
            if (missing != "Missing the Following: \n\n") MessageBox.Show(missing);
            else
            {
                if (playerinv.Checked)
                {
                    f.ClearPlayerList();
                    p.Inventory.AddItem(itm);
                    foreach (Item item in p.Inventory.Items)
                        f.AddToPlayerList(item.Title + " (" + item.mainIdentifier() + ") ");
                }
                else
                {
                    p.InLocation.Inventory.AddItem(itm);
                    f.AddToLocList(itm.Title + " (" + itm.mainIdentifier() + ") ");
                }
                Close();
            }           
        }

        private void Cancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void reset_Click(object sender, EventArgs e)
        {
            id1.Text = "";
            id2.Text = "";
            id3.Text = "";
            isContainer.Checked = false;
            isStationary.Checked = false;
            title.Text = "";
            desc.Text = "";
            playerinv.Checked = false;
            locinv.Checked = false;
        }
    }
}
